package com.geek.tutorial.itext.image;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Phrase;
import com.lowagie.text.Image;
import java.io.*;

public class TextWrapping {

	public ByteArrayOutputStream TextWrapping() throws Exception {
	
		Document document = new Document();
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
		PdfWriter.getInstance(document, buffer);
		document.open();

		for(int i = 0; i < 100; i++)
		{
			document.add(new Phrase("AAAA ")); // Code 1
		}		
		com.lowagie.text.Image image = com.lowagie.text.Image.getInstance("square.jpg");
		image.setAlignment(Image.RIGHT | Image.TEXTWRAP); // Code 2
		document.add(image);
		
		document.add(new Phrase("\n\n")); // Code 3                
		for(int i = 0; i < 100; i++)
		{
			document.add(new Phrase("BBBB "));
		}
		
		document.close();
                return buffer;
		
	}
	
	
	public static void main(String[] args) {
		try{
			TextWrapping textWrapping = new TextWrapping();
		}catch(Exception e){
			System.out.println(e);
		}
		
	}

}